package com.ruoyi.web.controller.admin.document;


import com.ruoyi.admin.domain.LlmDocumentSegments;
import com.ruoyi.admin.service.document.ILlmDocumentSegmentsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 切片控制器
 */
@RestController
@RequestMapping("/document/segment")
@RequiredArgsConstructor
public class LlmDocumentSegmentCollection extends BaseController {

    public final ILlmDocumentSegmentsService llmDocumentSegmentsService;

    /**
     * 通过文档 id 获取切片信息
     *
     * @param documentId 切片id
     * @param keyword    关键词
     * @return tableDataInfo
     */
    @GetMapping("/index")
    public TableDataInfo index(@RequestParam("documentId") String documentId,
                               @RequestParam(name = "keyword", defaultValue = "") String keyword) {
        return getDataTable(llmDocumentSegmentsService.getDocumentsSegments(documentId, keyword));
    }

    /**
     * 修改原文
     *
     * @param llmDocumentSegments 切片对象
     * @return ajax
     */
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody LlmDocumentSegments llmDocumentSegments) {
        return llmDocumentSegmentsService.edit(llmDocumentSegments) ? AjaxResult.success() : AjaxResult.error();
    }

    /**
     * 修改标签
     *
     * @param llmDocumentSegments 切片对象
     * @return ajax
     */
    @PutMapping("/editLabelData")
    public AjaxResult editLabelData(@RequestBody LlmDocumentSegments llmDocumentSegments) {
        return llmDocumentSegmentsService.editLabelData(llmDocumentSegments) ? AjaxResult.success() : AjaxResult.error();
    }

    /**
     * 通过id 获取切片详细信息
     *
     * @param id 切片id
     * @return ajax
     */
    @GetMapping("/detail/{id}")
    public AjaxResult detail(@PathVariable(name = "id") String id) {
        return AjaxResult.success(llmDocumentSegmentsService.detail(id));
    }

}
